package com.yanqu.road.server.manager.group;

import com.yanqu.road.entity.servercenter.ServerInfo;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cross.group.CrossGroupProto;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manger.ServerListMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.ConfigHelper;
import com.yanqu.road.utils.YanQuMessageUtils;

import java.util.List;

public class SystemGroupHelper {

    public static void notifyServerReload(int systemId){
        List<ServerInfo> serverInfoList = ServerListMgr.getOpenServerList();
        int channelId = ConfigHelper.getInt("channelId");
        CrossGroupProto.SystemServerGroupReloadNotifyMsg.Builder msg = CrossGroupProto.SystemServerGroupReloadNotifyMsg.newBuilder();
        msg.setSystemId(systemId);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.S_CROSS_SERVER_GROUP_RELOAD_NOTIFY_SYSTEM, msg);
        for(ServerInfo serverInfo : serverInfoList){
            if(serverInfo.getChannelId() == channelId){
                MessageHelper.sendPacket(serverInfo.getServerId(), 0, pbMsg);
            }
        }
    }

}